package com.imoresoft.magic.parser.templet;

import com.ambitor.grass.sql.dao.SuperDao;
import com.ambitor.grass.util.data.DataMap;
import com.ambitor.grass.util.data.IData;
import com.ambitor.grass.util.data.IDataset;

public class UserTempletParserFactory {

	public static IUserTempletParser instance(SuperDao superDao,
			IData userTempletStyle, IDataset itemList, IData buyerData,
			String title, int numPerTr) throws Exception {
		int templetId = userTempletStyle.getInt("TEMPLET_ID");
		IUserTempletParser templetParser = null;
		switch (templetId) {
		case 1: {
			templetParser = new UserTempletParser1(superDao, userTempletStyle,
					itemList, buyerData, title, numPerTr);
			return templetParser;
		}
		default: {
			templetParser = new UserTempletParser1(superDao, userTempletStyle,
					itemList, buyerData, title, numPerTr);
			return templetParser;
		}
		}
	}

	public static IUserTempletParser instance(SuperDao superDao,
			int templetStyleId, IDataset itemList, IData buyerData,
			String title, int numPerTr) throws Exception {
		IData userTempletStyle = initUserTempletStyle(superDao, templetStyleId);
		int templetId = userTempletStyle.getInt("TEMPLET_ID");
		IUserTempletParser templetParser = null;
		switch (templetId) {
		case 1: {
			templetParser = new UserTempletParser1(superDao, userTempletStyle,
					itemList, buyerData, title, numPerTr);
			return templetParser;
		}
		default: {
			templetParser = new UserTempletParser1(superDao, userTempletStyle,
					itemList, buyerData, title, numPerTr);
			return templetParser;
		}
		}
	}

	@SuppressWarnings("unchecked")
	private static IData initUserTempletStyle(SuperDao superDao,
			int templetStyleId) {
		IData param = new DataMap();
		param.put("TEMPLET_STYLE_ID", templetStyleId);
		IData userTempletStyle = null;
		try {
			userTempletStyle = superDao.queryByPK("TF_M_USER_TEMPLET_STYLE", param);
		} catch (Exception e) {
		}
		return userTempletStyle;
	}
}
